package com.aiyige.page.my.customer.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.aiyige.MyApp;
import com.aiyige.R;

/**
 * Created by xiachao on 2018/3/21.
 */

public class CustomerEntity implements Parcelable {


    String id;
    String name;
    String avatar;
    String phone;
    double totalTransactionPrice;
    int totalTransactionOrderCount;

    private CustomerEntity(Builder builder) {
        setId(builder.id);
        setName(builder.name);
        setAvatar(builder.avatar);
        setPhone(builder.phone);
        setTotalTransactionPrice(builder.totalTransactionPrice);
        setTotalTransactionOrderCount(builder.totalTransactionOrderCount);
        setBuyerId(builder.buyerId);
        setCustomerType(builder.customerType);
        setFollowupTime(builder.followupTime);
        setNextFollowupTime(builder.nextFollowupTime);
        setSex(builder.sex);
        setCustomerFrom(builder.customerFrom);
        setRemark(builder.remark);
    }

    protected CustomerEntity(Parcel in) {
        id = in.readString();
        name = in.readString();
        avatar = in.readString();
        phone = in.readString();
        totalTransactionPrice = in.readDouble();
        totalTransactionOrderCount = in.readInt();
        buyerId = in.readString();
        customerType = in.readString();
        followupTime = in.readString();
        nextFollowupTime = in.readString();
        sex = in.readString();
        customerFrom = in.readString();
        remark = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(id);
        dest.writeString(name);
        dest.writeString(avatar);
        dest.writeString(phone);
        dest.writeDouble(totalTransactionPrice);
        dest.writeInt(totalTransactionOrderCount);
        dest.writeString(buyerId);
        dest.writeString(customerType);
        dest.writeString(followupTime);
        dest.writeString(nextFollowupTime);
        dest.writeString(sex);
        dest.writeString(customerFrom);
        dest.writeString(remark);
    }

    public static final Creator<CustomerEntity> CREATOR = new Creator<CustomerEntity>() {
        @Override
        public CustomerEntity createFromParcel(Parcel in) {
            return new CustomerEntity(in);
        }

        @Override
        public CustomerEntity[] newArray(int size) {
            return new CustomerEntity[size];
        }
    };

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getBuyerId() {
        return buyerId == null ? "" : buyerId;
    }

    public void setBuyerId(String buyerId) {
        this.buyerId = buyerId;
    }

    String buyerId;

    String customerType;
    String followupTime;
    String nextFollowupTime;
    String sex;
    String customerFrom;
    String remark;

    public CustomerEntity(){

    }



    @Override
    public int describeContents() {
        return 0;
    }




    public void setName(String name) {
        this.name = name;
    }



    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }



    public void setPhone(String phone) {
        this.phone = phone;
    }



    public void setTotalTransactionPrice(double totalTransactionPrice) {
        this.totalTransactionPrice = totalTransactionPrice;
    }

    public void setTotalTransactionOrderCount(int totalTransactionOrderCount) {
        this.totalTransactionOrderCount = totalTransactionOrderCount;
    }


    public void setFollowupTime(String followupTime) {
        this.followupTime = followupTime;
    }

    public void setNextFollowupTime(String nextFollowUpTime) {
        this.nextFollowupTime = nextFollowUpTime;
    }

    public void setCustomerType(String customerType) {
        this.customerType = customerType;
    }


    public boolean islady() {
        return !TextUtils.isEmpty(sex)&&  sex.equals("f");
    }

    public boolean isMan() {
        return !TextUtils.isEmpty(sex)&&  sex.equals("2");
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public void setCustomerFrom(String customerFrom) {
        this.customerFrom = customerFrom;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getName() {
        return name == null ? "" : name;
    }

    public String getAvatar() {
        return avatar == null ? "" : avatar;
    }

    public String getPhone() {
        return phone == null ? "" : phone;
    }

    public double getTotalTransactionPrice() {
        return totalTransactionPrice;
    }

    public int getTotalTransactionOrderCount() {
        return totalTransactionOrderCount;
    }

    public String getCustomerType() {
        return customerType == null ? "" : customerType;
    }

    public String getFollowupTime() {
        return followupTime == null ? "0" : followupTime;
    }

    public String getNextFollowupTime() {
        return nextFollowupTime == null ? "0" : nextFollowupTime;
    }

    public String getSex() {
        return sex == null ? "" : sex;
    }

    public String getSexName() {
        String sexName = "";
        if (!TextUtils.isEmpty(sex)) {
            if (sex.equals("f")) {
                return MyApp.getAppContext().getResources().getString(R.string.female);
            }
            else if (sex.equals("m")) {
                return MyApp.getAppContext().getResources().getString(R.string.male);
            }
            else if (sex.equals("x")) {
                return MyApp.getAppContext().getResources().getString(R.string.unknown);
            }
        }
        return sexName;
    }

    public String getCustomerFrom() {
        return customerFrom == null ? "" : customerFrom;
    }

    public String getRemark() {
        return remark == null ? "" : remark;
    }

    public String getId() {
        return id == null ? "" : id;
    }

    public void setId(String id) {
        this.id = id;
    }


    public static final class Builder {
        private String id;
        private String name;
        private String avatar;
        private String phone;
        private double totalTransactionPrice;
        private int totalTransactionOrderCount;
        private String buyerId;
        private String customerType;
        private String followupTime;
        private String nextFollowupTime;
        private String sex;
        private String customerFrom;
        private String remark;

        private Builder() {
        }

        public Builder id(String id) {
            this.id = id;
            return this;
        }

        public Builder name(String name) {
            this.name = name;
            return this;
        }

        public Builder avatar(String avatar) {
            this.avatar = avatar;
            return this;
        }

        public Builder phone(String phone) {
            this.phone = phone;
            return this;
        }

        public Builder totalTransactionPrice(double totalTransactionPrice) {
            this.totalTransactionPrice = totalTransactionPrice;
            return this;
        }

        public Builder totalTransactionOrderCount(int totalTransactionOrderCount) {
            this.totalTransactionOrderCount = totalTransactionOrderCount;
            return this;
        }

        public Builder buyerId(String buyerId) {
            this.buyerId = buyerId;
            return this;
        }

        public Builder customerType(String customerType) {
            this.customerType = customerType;
            return this;
        }

        public Builder lastFollowupTime(String followupTime) {
            this.followupTime = followupTime;
            return this;
        }

        public Builder nextFollowupTime(String nextFollowupTime) {
            this.nextFollowupTime = nextFollowupTime;
            return this;
        }

        public Builder sex(String sex) {
            this.sex = sex;
            return this;
        }

        public Builder customerFrom(String customerFrom) {
            this.customerFrom = customerFrom;
            return this;
        }

        public Builder remark(String remark) {
            this.remark = remark;
            return this;
        }

        public CustomerEntity build() {
            return new CustomerEntity(this);
        }
    }
}
